﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="departmentList.aspx.cs"
    Inherits="PeisongWeb.admin.departmentList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<%@ Register TagName="top" Src="controls/top.ascx" TagPrefix="uc1" %>
<%@ Register TagName="menu" Src="controls/menu.ascx" TagPrefix="uc2" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>部门管理</title>
    <!--#include file="style.inc"-->
    <script type="text/javascript" src="../app_common/scripts/jquery-cn.js"></script>
    <script type="text/javascript">
        function checkLength() {
            var dname = document.getElementById("txt_DepartmentName");
            var dsort = document.getElementById("txt_sort")
            if (dname.value.length == 0) {
                alert("请输入部门名称！");
                return false;
            }
            else {
                var test = /^[0-9]*[1-9][0-9]*$/;
                if (test.test(dsort.value)) {
                    return true;
                }
                else {
                    alert("请输入正整数！");
                    return false;
                }
            }
        }

        function checkstatus(obj) {
            if ($("[id$='" + obj.id + "']").parent().find("input:hidden").val()=="True") {
                if (confirm("如果该部门有子部门，则禁用该部门会是该部门下的子部门也被禁用，确认要禁用吗？")) {
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                if (confirm("请确认该部门的上级部门没有被禁用，否则无法启用，请确认！")) {
                    return true;
                }
                else {
                    return false;
                }
            }
            
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:ScriptManager ID="sm1" runat="server" />
    <uc1:top ID="Top1" runat="server" />
    <uc2:menu ID="Menu1" runat="server" />
    <div id="admin-body">
        <h2 class="section-cms">
            部门管理</h2>
        <asp:UpdatePanel runat="server" ID="UP1" UpdateMode="Always">
            <ContentTemplate>
                <span>
                    <asp:Button ID="btn_addDepartment" runat="server" Text="新增" OnClick="btn_addDepartment_Click" />
                </span>
                <p>
                    &nbsp;&nbsp;</p>
                <ext:Panel ID="Panel1" runat="server" Title="查询部门" BodyStyle="padding:5px 5px 0"
                    Width="960" Frame="true" ButtonAlign="Center">
                    <Body>
                        <div id="admin_edit_content_search">
                            <ul>
                                <li style="width: 240px">
                                    <label style="width: auto">
                                        部门名称</label>
                                    <asp:DropDownList ID="ddl_pdt" runat="server" AutoPostBack="true" DataTextField="department"
                                        DataValueField="dId" OnSelectedIndexChanged="ddl_pdt_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </li>
                                <li style="width: 240px">
                                    <label style="width: auto">
                                        子部门名称</label>
                                    <asp:DropDownList ID="ddl_cdt" runat="server" DataTextField="department" DataValueField="dId">
                                    </asp:DropDownList>
                                </li>
                                <li style="width: auto">
                                    <asp:LinkButton ID="lbn_select" runat="server" Text="［搜索］" CausesValidation="false"
                                        OnClick="lbn_select_Click"></asp:LinkButton>
                                    <asp:LinkButton ID="lbn_reset" runat="server" Text="[重置]" CausesValidation="false"
                                        OnClick="lbn_reset_Click"></asp:LinkButton>
                                </li>
                            </ul>
                        </div>
                    </Body>
                </ext:Panel>
                <p>
                    &nbsp;&nbsp;</p>
                <div id="admin_list_content" style="width: 960px;">
                    <table cellpadding="0" cellspacing="0" style="text-align: center">
                        <tr class="header-row">
                            <th style="text-align: center">
                                序号
                            </th>
                            <th style="text-align: center">
                                部门名称
                            </th>
                            <th style="text-align: center">
                                上级部门
                            </th>
                            <th style="text-align: center">
                                状态
                            </th>
                            <th style="text-align: center">
                                操作
                            </th>
                        </tr>
                        <asp:Repeater ID="rpt_list" runat="server" OnItemCommand="rpt_list_ItemCommand">
                            <ItemTemplate>
                                <tr class='<%# Container.ItemIndex%2==0? "row-alt":"alt"  %>' style="color: Black">
                                    <td>
                                        <%# Container.ItemIndex+1 %>
                                    </td>
                                    <td>
                                        <%# DataBinder.Eval(Container.DataItem, "department")%>
                                    </td>
                                    <td>
                                        <%# DataBinder.Eval(Container.DataItem, "parentdepartment")%>
                                    </td>
                                    <td>
                                        <%# DataBinder.Eval(Container.DataItem, "dstatus")%>
                                    </td>
                                    <td>
                                        <asp:LinkButton ID="lblEdit" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"dId") %>'
                                            runat="server">修改</asp:LinkButton>
                                        <asp:HiddenField ID="hdisShow" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"isShow") %>' />    
                                        <asp:LinkButton CommandName="Del" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"dId") %>'
                                            OnClientClick="return checkstatus(this)"
                                            runat="server" ID="lblDel" Text='<%# DataBinder.Eval(Container.DataItem,"isshowname") %>'></asp:LinkButton>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </table>
                </div>
                <ext:Window ID="departmentdetail" runat="server" Title="部门编辑" Height="500px" Width="600px"
                    BodyStyle="padding: 6px; background-color: #fff;" AutoScroll="true" Modal="True"
                    Resizable="false" ShowOnLoad="false" Draggable="false" Icon="ApplicationViewDetail">
                    <Body>
                        <div id="admin_edit_content">
                            <ul>
                                <li>
                                    <label>
                                        部门名称</label>
                                    <asp:TextBox ID="txt_DepartmentName" runat="server" Width="100px"></asp:TextBox>
                                    <asp:HiddenField ID="hdtype" runat="server" />
                                    <asp:HiddenField ID="hddid" runat="server" />
                                </li>
                                <li>
                                    <label>
                                        上级部门名称</label>
                                    <asp:DropDownList ID="ddl_parentDepartment" runat="server" DataTextField="department"
                                        DataValueField="dId" Width="100px">
                                    </asp:DropDownList>
                                </li>
                                <li>
                                    <label>
                                        排序值</label>
                                    <asp:TextBox ID="txt_sort" runat="server" Text='1' Width="100px"></asp:TextBox>
                                </li>
                                <li>
                                    <label>
                                        &nbsp;
                                    </label>
                                    <asp:Button ID="btn_Save" runat="server" Text="保存" OnClientClick="return checkLength(this)"
                                        OnClick="btn_Save_Click" />
                                </li>
                            </ul>
                        </div>
                    </Body>
                </ext:Window>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
